﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mini_Project
{
    class Program
    {
        static void Main1(int test)
        {
            DateTime dtStart;
            double noveltyPrecent;
            double similatiryThreshold;

            RecommenderSystem rs = new RecommenderSystem();
            //rs.Load("MovieLens/u.data");
            rs.Load("../../MovieLens/u.data", 0.95);
            rs.TrainBaseModel(5);

            // first graph - run our new method on all algos, with static precentages, and various lengths
            List<string> lMethods = new List<string>();
            lMethods.Add("Pearson");
            lMethods.Add("Cosine");
            lMethods.Add("SVD");
            lMethods.Add("NNPearson");
            lMethods.Add("NNCosine");
            lMethods.Add("NNSVD");
            lMethods.Add("Popularity");
/*          List<int> lLengths = new List<int>();
            lLengths.Add(1);
            lLengths.Add(5);
            lLengths.Add(10);
            lLengths.Add(20);
            noveltyPrecent = .3;
            similatiryThreshold = .25;
            DateTime dtStart = DateTime.Now;
            Dictionary<int, Dictionary<string, Dictionary<string, double>>> dResults = rs.ComputeDifferentLengths(lMethods, lLengths, noveltyPrecent, similatiryThreshold);
            Console.WriteLine("Execution time was " + Math.Round((DateTime.Now - dtStart).TotalSeconds, 0));
            rs.DisplayInExcel(dResults);
*/

            // run algos on different similarity threshold percentages with a constant best length, 
            // and a constant percentage of novelty items
            // similarity threshold - when distance is higher than that - it is a novelty item
            noveltyPrecent = 0.3;
            int length = 10;
            List<double> simThreshold = new List<double>();
            simThreshold.Add(.1);
            simThreshold.Add(.25);
            simThreshold.Add(.4);
            simThreshold.Add(.55);
            simThreshold.Add(.7);
            if (test == 1)
            {
                //results: threshold -> algo -> precision -> recall
                dtStart = DateTime.Now;
                Dictionary<double, Dictionary<string, Dictionary<string, double>>> thresholdResults = rs.ComputeDifferentThreshold(lMethods, simThreshold, noveltyPrecent, length);
                Console.WriteLine("Execution time was " + Math.Round((DateTime.Now - dtStart).TotalSeconds, 0));
                rs.DisplayInExcelPrecent(thresholdResults, "Similarity Threshold");
            }


            // run algo on different percentages of novelty items - how many items have to be "new items"
            similatiryThreshold = .25;
            List<double> novPrecent = new List<double>();
            novPrecent.Add(.1);
            novPrecent.Add(.15);
            novPrecent.Add(.2);
            novPrecent.Add(.25);
            novPrecent.Add(.3);
            novPrecent.Add(.35);
            novPrecent.Add(.4);
            novPrecent.Add(.45);
            novPrecent.Add(.5);
            //results: novelty percentage -> algo -> precision -> recall
            if (test == 2)
            {
                dtStart = DateTime.Now;
                Dictionary<double, Dictionary<string, Dictionary<string, double>>> NoveltyResults = rs.ComputeDifferentNoveltyPercent(lMethods, novPrecent, similatiryThreshold, length);
                Console.WriteLine("Execution time was " + Math.Round((DateTime.Now - dtStart).TotalSeconds, 0));
                rs.DisplayInExcelPrecent(NoveltyResults, "Novelty Percent");
            }

            Console.WriteLine("Complete");

            Console.ReadLine();
        }

        static void Main2()
        {
            RecommenderSystem rs = new RecommenderSystem();
            rs.Load("../../MovieLens/u.data");

            List<string> recs = rs.Recommend("Pearson", "6", 20, 0);
            List<string> new_recs = rs.NoveltyRecommend("Pearson", "6", 20, .3, .4);

            for (int i = 0; i < 20; i++)
            {
                Console.WriteLine("recs: " + recs[i] + " vs new_recs: " + new_recs[i]);
            }

            Console.ReadLine();

        }

        static void Main(string[] Args)
        {
            Main2();
            Main1(1);       /* Test Similarity Threshold */
            //Main1(2);     /* Test Novelty Percent */
        }
    }
}
